﻿using Microsoft.Extensions.Configuration;
using SqlSugar;

namespace ITSM.Model
{
    public class BaseDB
    {
        protected SqlSugarClient db;
        public BaseDB()
        {
            db = GetClient();
            //db.Aop.OnDiffLogEvent = it =>
            //{
            //    Console.WriteLine(it);
            //    //操作前记录  包含： 字段描述 列名 值 表名 表描述
            //    var editBeforeData = it.BeforeData;//插入Before为null，之前还没进库
            //    //操作后记录   包含： 字段描述 列名 值  表名 表描述
            //    var editAfterData = it.AfterData;
            //    var sql = it.Sql;
            //    var parameter = it.Parameters;
            //    var data = it.BusinessData;//这边会显示你传进来的对象
            //    var time = it.Time;
            //    var diffType = it.DiffType;//enum insert 、update and delete 
            //};
        }
        public static SqlSugarClient GetClient()
        {
            string ConnectionString = AppHelper.ReadAppSettings("ConnectionStrings", "SqlServer");
            SqlSugarClient db = new(
                new ConnectionConfig()
                {
                    ConnectionString = ConnectionString,
                    DbType = DbType.SqlServer,
                    IsAutoCloseConnection = true,
                    InitKeyType = InitKeyType.Attribute, //从实体特性中读取主键自增列信息
                }
                );
            return db;
        }
    }
    public static class BaseDBHR
    {
        public static SqlSugarClient GetClient()
        {
            string ConnectionString = AppHelper.ReadAppSettings("ConnectionStrings", "SqlServerHR");
            SqlSugarClient db = new(
                new ConnectionConfig()
                {
                    ConnectionString = ConnectionString,
                    DbType = DbType.SqlServer,
                    IsAutoCloseConnection = true,
                    InitKeyType = InitKeyType.Attribute, //从实体特性中读取主键自增列信息
                }
                );
            return db;
        }
    }
}
